package org.cargloss.cp.controller.modul.menus;



import org.cargloss.cp.model.Menus;

import util.hibernate.DAO;

import com.opensymphony.xwork2.ActionSupport;

public class ActionJQGridCrud extends ActionSupport {
	private static final long serialVersionUID = -5933849517817526086L;

	private String id;
	private String name;
	private String oper;

	public String getOper() {
		return oper;
	}

	public void setOper(String oper) {
		this.oper = oper;
	}

	public String execute() {
		if (getOper().equals("edit")) {
			return update();
		} else if (getOper().equals("add")) {
			return insert();
		} else {
			return delete();
		}
	}

	public String insert() {
		DAO<Integer> dao = new DAO<Integer>();
		Menus Menus = new Menus();
		Menus.setName(getName());
		dao.insert(Menus);
		dao.close();
		return SUCCESS;
	}

	public String update() {
		DAO<Integer> dao = new DAO<Integer>();
		Menus Menus = (Menus) dao.find(Menus.class, Integer.valueOf(getId()));
		Menus.setName(getName());
		dao.update(Menus);
		return SUCCESS;
	}

	public String delete() {
		DAO<Integer> dao = new DAO<Integer>();
		Menus delete = (Menus) dao.find(Menus.class, Integer.valueOf(getId()));
		dao.delete(delete);
		dao.close();
		return SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}



	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
